package view;

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import controller.*;
import model.*;
/**
 * This class is to create a formulary to add a new contact
 * @author Estelle
 *
 */

public class Formulaire {
	
	private JFrame form = new JFrame();
	private JPanel container = new JPanel();
	private JLabel label = new JLabel("Formulaire");
	private BinForm b1 = new BinForm();
	private Carnet storage = new Carnet("");
//--------------------------------------------------------------------------------------------------------------------------------------------------------
		
	/**
	 * The constrcutor takes the jframe window because of the action listener of the button save
	 * @param window
	 */
	  
	public Formulaire(JFrame window){
		FileDoc file = new FileDoc(); 
		this.storage.copy(file.recupCarnet("Estelle"));
		
		//--------------------------------------------------------------------------------------------------------------------------------------------------------
		/**
		 * style window
		 */
		form.setTitle("Formulaire");
		form.setSize(200, 400);
		form.setLocationRelativeTo(null);
		
		form.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);             
		form.setVisible(true);
		
		container.setBackground(Color.white);
		container.setLayout(new BorderLayout());
		//--------------------------------------------------------------------------------------------------------------------------------------------------------
		
		// text area
		JPanel top = new JPanel();        
		
		//--------------------------------------------------------------------------------------------------------------------------------------------------------
		
	    /**
	     * creation of the saveButton
	     */
	    JButton saveButton = new JButton("Save");
	    saveButton.setBounds(50, 60, 80, 30);
	           
	    saveButton.setToolTipText("To save your new contact");
	           
	    saveButton.addActionListener(new SaveFormulaire(b1, form, window));
	    
	    //--------------------------------------------------------------------------------------------------------------------------------------------------------
		
		/**
		 * set of the element in the frame
		 */
		top.add(label);
		b1.addToPannel(top);
		top.add(saveButton);
		
		//--------------------------------------------------------------------------------------------------------------------------------------------------------
		// END 
		form.setContentPane(top);
		form.setVisible(true);     
		//--------------------------------------------------------------------------------------------------------------------------------------------------------
		  
	}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
	/**
	 * Getter and setter of each elements
	 * 
	 */
	public JFrame getForm() {
		return form;
	}

	public void setForm(JFrame form) {
		this.form = form;
	}

	public JPanel getContainer() {
		return container;
	}

	public void setContainer(JPanel container) {
		this.container = container;
	}

	public JLabel getLabel() {
		return label;
	}

	public void setLabel(JLabel label) {
		this.label = label;
	}

	public BinForm getB1() {
		return b1;
	}

	public void setB1(BinForm b1) {
		this.b1 = b1;
	}

	public Carnet getStorage() {
		return storage;
	}

	public void setStorage(Carnet storage) {
		this.storage = storage;
	}
}
